package com.c2soft.ncmxReport.service;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.util.Rotation;
import org.springframework.stereotype.Service;

import com.c2soft.ncmxReport.controller.ChartController;


/**
 * The Class ChartService.
 */
@Service
public class ChartService {
	
	/**
	 * Creates the pie chart.
	 *
	 * @param pdset the pdset
	 * @param chartTitle the chart title
	 * @return the j free chart
	 */
	static final Logger logger = LogManager.getLogger(ChartController.class);
	
	
	public JFreeChart createPieChart(PieDataset pdset, String chartTitle) {
		logger.debug("Entering createPieChart with data {} and title", pdset.getKeys(),chartTitle );
		JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, pdset,
				true, true, false);
		PiePlot3D plot = (PiePlot3D) chart.getPlot();
		plot.setStartAngle(290);
		plot.setDirection(Rotation.CLOCKWISE);
		plot.setForegroundAlpha(0.5f);
		return chart;

	}

	
	/**
	 * Creates the bar chart.
	 *
	 * @param chartTitle the chart title
	 * @param catogaryAxisLabel the catogary axis label
	 * @param valueAxisLabel the value axis label
	 * @param barDset the bar dset
	 * @return the j free chart
	 */
	public JFreeChart createBarChart(String chartTitle,
			String catogaryAxisLabel, String valueAxisLabel,
			CategoryDataset barDset) {
		JFreeChart chart = ChartFactory.createBarChart3D(chartTitle,
				catogaryAxisLabel, catogaryAxisLabel, barDset,
				PlotOrientation.VERTICAL, true, true, false);

		return chart;

	}


	/**
	 * Creates the line chart.
	 *
	 * @param chartTitle the chart title
	 * @param catogaryAxisLabel the catogary axis label
	 * @param valueAxisLabel the value axis label
	 * @param barDset the bar dset
	 * @return the j free chart
	 */
	public JFreeChart createLineChart(String chartTitle,
			String catogaryAxisLabel, String valueAxisLabel,
			XYSeriesCollection barDset) {
		JFreeChart chart = ChartFactory.createXYLineChart(chartTitle,
				catogaryAxisLabel, valueAxisLabel, barDset,
				PlotOrientation.VERTICAL, true, true, false);
		return chart;

	}


	/**
	 * Creates the area chart.
	 *
	 * @param chartTitle the chart title
	 * @param catogaryAxisLabel the catogary axis label
	 * @param valueAxisLabel the value axis label
	 * @param barDset the bar dset
	 * @return the j free chart
	 */
	public JFreeChart createAreaChart(String chartTitle,
			String catogaryAxisLabel, String valueAxisLabel,
			XYSeriesCollection barDset) {
		JFreeChart chart = ChartFactory.createXYAreaChart(chartTitle,
				catogaryAxisLabel, valueAxisLabel, barDset,
				PlotOrientation.VERTICAL, true, true, false);

		return chart;

	}

	
	/**
	 * Creates the time chart.
	 *
	 * @param chartTitle the chart title
	 * @param catogaryAxisLabel the catogary axis label
	 * @param valueAxisLabel the value axis label
	 * @param dSet the d set
	 * @return the j free chart
	 */
	public JFreeChart createTimeChart(String chartTitle,
			String catogaryAxisLabel, String valueAxisLabel,
			TimeSeriesCollection dSet) {
		JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle,
				catogaryAxisLabel, valueAxisLabel, dSet, true, true, false);

		return chart;

	}
}
